package com.beagle.njddapp.ui.presenter;

import com.beagle.njddapp.base.BasePresenter;
import com.beagle.njddapp.base.OilApiService;
import com.beagle.njddapp.base.RetrofitHttp;
import com.beagle.njddapp.bean.oil.OilBean;
import com.beagle.njddapp.net.BaseOilHttpResponse;
import com.beagle.njddapp.net.HttpResponseObserver;
import com.beagle.njddapp.net.RxSchedulers;
import com.beagle.njddapp.ui.view.OilManagerView;
import com.blankj.utilcode.util.LogUtils;


import okhttp3.RequestBody;

/**
 * @author hxx
 * @date 2021-03-02 22:33
 */
public class OilManagerPresenter extends BasePresenter<OilManagerView> {
    private OilApiService apiService;

    public OilManagerPresenter() {
        retrofit2.Retrofit retrofit = RetrofitHttp.provideRetrofit();
        //获取接口对象
        apiService = retrofit.create(OilApiService.class);

    }

    public void myCar(){
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json;charset=UTF-8"),"{}");
        apiService.myCard(body).compose(RxSchedulers.compose()).safeSubscribe(new HttpResponseObserver<BaseOilHttpResponse<OilBean>>() {
            @Override
            public void success(BaseOilHttpResponse<OilBean> oilHttpResponse) {
                LogUtils.d("success");
                if (oilHttpResponse!=null){
                    getView().showOild(oilHttpResponse.result);
                }

            }

            @Override
            public void error(int code, String message) {
                getView().onError(message);
            }
        });
    }

//    public String getTaskCreateJsonReq(JSONObject json){
//
//        StringBuffer req = new StringBuffer();
//        try {
//            String encode = URLEncoder.encode(json.toJSONString(), "UTF-8");
//            req.append("?data=" +encode);
//        } catch (UnsupportedEncodingException e){
//            req.append("?data=");
//        }
//
//
//        return req.toString();
//    }



}
